package com.access.db;

import access.model.AccessPolicy;

/**
 * Created by koujx on 2016/7/1.
 */
public class PolicyCache {
    private String key;
    private AccessPolicy policy;
    private long startTime;
    private int counts;//调用次数
    private double ratio;//相关数据量所占的比重
    private boolean expired;
    private double weight;

    public PolicyCache(AccessPolicy policy, long startTime, double ratio, boolean expired) {
        this.policy = policy;
        this.startTime = startTime;
        this.ratio = ratio;
        this.expired = expired;
        this.counts = 0;
        this.weight = ratio;
    }

    public double updateWeight(){
        double newW = 1000*(counts/ PolicyCacheManager.cacheTime)+ratio;
        this.setWeight(newW);
        return newW;
    }

    public String getKey() {
        return key;
    }

    public void setKey(String key) {
        this.key = key;
    }

    public AccessPolicy getPolicy() {
        return policy;
    }

    public void setPolicy(AccessPolicy policy) {
        this.policy = policy;
    }

    public long getStartTime() {
        return startTime;
    }

    public void setStartTime(long startTime) {
        this.startTime = startTime;
    }

    public int getCounts() {
        return counts;
    }

    public void setCounts(int counts) {
        this.counts = counts;
    }

    public double getRatio() {
        return ratio;
    }

    public void setRatio(double ratio) {
        this.ratio = ratio;
    }

    public boolean isExpired() {
        return expired;
    }

    public void setExpired(boolean expired) {
        this.expired = expired;
    }

    public double getWeight() {
        return weight;
    }

    public void setWeight(double weight) {
        this.weight = weight;
    }
}
